import 'package:basic_common/app_theme.dart';
import 'package:basic_common/common_exports.dart';
import 'package:basic_home/home_page.dart';
import 'package:basic_message/message_page.dart';
import 'package:basic_patient/patient_page.dart';
import 'package:basic_profile/profile_page.dart';

import 'main_tab_controller.dart';

/// 主页tab界面
class MainTabPage extends GetView<MainTabController> {
  List<BottomNavigationBarItem>? _list;
  final pageList = [HomePage(), PatientPage(), MessagePage(), ProfilePage()];
  @override
  Widget build(BuildContext context) {
    Get.put(MainTabController());
    ScreenHelper.init(context);
    return WillPopScope(
      onWillPop: () {
        return controller.exitApp();
      },
      child: Scaffold(
        // appBar: AppBar(title: Obx(() => Text(controller.navTitles[controller.index.value])),centerTitle: true,leading: SizedBox.shrink(),),
        body: Obx(() => IndexedStack(
              index: controller.index.value,
              children: pageList,
            )),
        bottomNavigationBar: Obx(() => BottomNavigationBar(
              type: BottomNavigationBarType.fixed,
              items: _buildBottomNavigationBarItem(),
              fixedColor: AppTheme.primyColor,
              currentIndex: controller.index.value,
              onTap: (value) {
                controller.index.value = value;
              },
            )),
      ),
    );
  }

  /// 构建选项
  List<BottomNavigationBarItem> _buildBottomNavigationBarItem() {
    if (_list == null) {
      var _tabImages = [
        [
          Image.asset(
            'assets/tab/tab_home_nor.png',
            width: 25.0,
            color: AppTheme.dartTextColor,package:"basic_common"
          ),
          Image.asset('assets/tab/tab_home_sel.png',
              width: 25.0, color: AppTheme.primyColor,package:"basic_common"),
        ],
        [
          Image.asset('assets/tab/tab_patient_nor.png',
              width: 25.0, color: AppTheme.dartTextColor,package:"basic_common"),
          Image.asset('assets/tab/tab_patient_sel.png',
              width: 25.0, color: AppTheme.primyColor,package:"basic_common")
        ],
        [
          Image.asset('assets/tab/tab_msg_nor.png',
              width: 25.0, color: AppTheme.dartTextColor,package:"basic_common"),
          Image.asset('assets/tab/tab_msg_sel.png',
              width: 25.0, color: AppTheme.primyColor,package:"basic_common")
        ],
        [
          Image.asset('assets/tab/tab_mine_nor.png',
              width: 25.0, color: AppTheme.dartTextColor,package:"basic_common"),
          Image.asset('assets/tab/tab_mine_sel.png',
              width: 25.0, color: AppTheme.primyColor,package:"basic_common")
        ]
      ];
      _list = List.generate(controller.navTitles.length, (i) {
        return BottomNavigationBarItem(
          icon: _tabImages[i][0],
          activeIcon: _tabImages[i][1],
          label: controller.navTitles[i],
        );
      });
    }
    return _list!;
  }
}
